'''
两堆石头的bash游戏
'''
import random


def f(a, b, limit):
    maxi = max(a, b)
    sg = [0] * (maxi + 1)
    for i in range(1, maxi + 1):
        appeared = [False] * (limit + 1)
        for j in range(1, limit + 1):
            if i - j < 0: break
            appeared[sg[i - j]] = True
        for s in range(limit + 1):
            if not appeared[s]:
                sg[i] = s
                break
    # print(a, b, limit)
    # print(*[(f'sg({i})', s) for i, s in enumerate(sg)])
    return (sg[a] ^ sg[b]) != 0


def f2(a, b, limit):
    return ((a % (limit + 1)) ^ (b % (limit + 1))) != 0


for _ in range(100):
    a = random.randint(1, 100)
    b = random.randint(1, 100)
    limit = random.randint(1, 10)
    r1 = f(a, b, limit)
    r2 = f2(a, b, limit)
    if r1 != r2:
        print(a, b, limit)
        print(r1, r2)
print('done')
